package com.mytrans.transaction;

import org.springframework.core.NamedThreadLocal;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class DefaultTokenManager implements TokenManager{


    public long sequence = 0;

    private long getSequence(){
        return sequence++;
    }

    static{

    }

    private static final ThreadLocal<Map<String, String>> LOCAL_TOKEN = new NamedThreadLocal<>("local_token");

    @Override
    public String initToken() {
        String key = UUID.randomUUID().toString();
        Map<String, String> map = new HashMap<>();
        map.put("token", key);
        LOCAL_TOKEN.set(map);
        return key;
    }

    @Override
    public String getLocalToken() {
        return LOCAL_TOKEN.get().get("token");
    }

}
